package lan.battletank.main;

import lan.battletank.element.BaseBattleUnitElement;
import lan.battletank.element.EnemyBulletEntity;
import lan.battletank.element.EnemyEntity;
import lan.battletank.element.IndicatorEntity;
import lan.battletank.element.TankEntity;
import lan.battletank.environment.EnvConst;
import lan.battletank.logic.EnemyLogic;

public class GameStatus {

    /** Record the turns played */
    public static int currentTurn;

    /** The state of the game. One of IN_BATTLE, PAUSE, LOSE, or WIN */
    private static int gameStatus;

    /** The state of the battle. See EnvConst's Battle Status. */
    private static int battleStatus;

    public static void setGameStatus(int gs, IndicatorEntity indicator) {
        gameStatus = gs;
        indicator.setGameStatus(gs);
    }

    public static void setBattleStatus(int bs, IndicatorEntity indicator) {
        battleStatus = bs;
        indicator.setBattleStatus(bs);
    }

    public static void checkGameStatus(TankEntity player, EnemyEntity enemy, EnemyBulletEntity bullet, IndicatorEntity indicator) {
        if (enemy.getHP() == 0) {
            setGameStatus(EnvConst.GAME_WIN, indicator);
        }
        if (!player.isAlive) {
            setGameStatus(EnvConst.GAME_LOSE, indicator);
        }
        if (!indicator.isShowingMessage()) {
            if (battleStatus == EnvConst.BATTLE_PLAYER_TURN_END) {
            	if (!EnemyLogic.inAction) {
            		setBattleStatus(EnvConst.BATTLE_ENEMY_TURN, indicator);
                    EnemyLogic.inAction = true;
                    EnemyLogic.enemyFire(enemy, bullet, indicator);
            	}
            } else if (battleStatus == EnvConst.BATTLE_ENEMY_TURN && !EnemyLogic.inAction) {
                setBattleStatus(EnvConst.BATTLE_ENEMY_TURN_END, indicator);
            } else if (battleStatus == EnvConst.BATTLE_ENEMY_TURN_END) {
                setBattleStatus(EnvConst.BATTLE_PLAYER_TURN, indicator);
            }
        }
    }

    public static int getGameStatus() {
        return gameStatus;
    }

    public static int getBattleStatus() {
        return battleStatus;
    }
}
